package cn.net.msg.cxf.webservice.impl;

import java.io.IOException;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import cn.net.msg.cxf.webservice.IScoreWebService;
import cn.net.msg.model.ReturnRankBean;
import cn.net.msg.model.TbScore;
import cn.net.msg.service.TbScoreService;

/**
 * <p>
 * FileName: ScoreWebServiceImpl.java
 * </p>
 * <p>
 * Description: Score的cxf接口实现类
 * <p>
 * Copyright: surepassserver(c) 2012
 * </p>
 * <p>
 * @author Vic Su
 * </p>
 * <p>
 * @content andyliu900@gmail.com
 * </p>
 * <p>
 * @version 1.0
 * </p>
 * <p>
 * CreatDate: 2012-11-21 下午10:26:04
 * </p>
 * <p>
 * Modification History
 */

@WebService
@SOAPBinding(style = Style.RPC)
@SuppressWarnings("deprecation")
public class ScoreWebServiceImpl implements IScoreWebService {

    private static final long serialVersionUID = -7574227471498726524L;

    @Resource(name="tbScoreService")
    TbScoreService service;

    @Override
    public void submitScore(String submitScoreJSONObject) {
        // TODO Auto-generated method stub
        try {
            //应该允许再次提交，没有记录的话，新增一条记录；已经存在记录的话，更新该条记录的分数值
            ObjectMapper objectMapper = new ObjectMapper();
            TbScore tbScore = objectMapper.readValue(submitScoreJSONObject, TbScore.class);
            boolean isExsit = service.isExsit(tbScore);
            if (!isExsit) {
                service.save(tbScore);
            } else {
                service.updateScoreRank(tbScore);
            }
        } catch (JsonParseException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public ReturnRankBean getScoreRank(long userid, String examFileIdsString) {
        // TODO Auto-generated method stub
        return service.getScoreRank(userid, examFileIdsString);
    }

}
